package com.example.dbpage.adapter

import android.support.v7.recyclerview.extensions.ListAdapter
import android.support.v7.util.DiffUtil
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.ViewGroup
import com.example.dbpage.R

class RecyclerAdapter : ListAdapter<String, Viewholder>(diffCallback) {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Viewholder {
        return Viewholder(LayoutInflater.from(parent.context).inflate(R.layout.item_layout, parent, false))
    }

    override fun onBindViewHolder(holder: Viewholder, position: Int) {
        holder.textView.text = getItem(position)
    }

    companion object {
        var diffCallback = object : DiffUtil.ItemCallback<String>() {
            override fun areItemsTheSame(oldItem: String?, newItem: String?): Boolean {
                return TextUtils.equals(oldItem, newItem)
            }

            override fun areContentsTheSame(oldItem: String?, newItem: String?): Boolean {
                return TextUtils.equals(oldItem, newItem)
            }
        }
    }
}


